/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.ui.controls;

import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JList;

/**
 *
 * @author empcl_000
 */
public class PCLList extends JList<Object> {

    private boolean required;

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    
    
    public  void setStelectonByValue( String value) {

        String[] Values = value.split(";");

        ArrayList<Integer> ftd = new ArrayList<Integer>();
        for (int i = 0; i < Values.length; i++) {

            for (int x = 0; x < this.getModel().getSize(); x++) {

                if (Values[i].trim().equals(this.getModel().getElementAt(x))) {
                    ftd.add(x);
                }
            }
        }

        int[] ii = new int[ftd.size()];
        for (int hh = 0; hh < ftd.size(); hh++) {
            ii[hh] = ftd.get(hh);
        }

        this.setSelectedIndices(ii);
      
    }

    public  String getValue( ) {

        String returnData = "";
        try {

            for (int i = 0; i < this.getSelectedValuesList().size(); i++) {

                ac.ui.controls.Item itemCate = (ac.ui.controls.Item) this.getSelectedValuesList().get(i);

                returnData += itemCate.getValue() + ";";
            }

        } catch (Exception ex) {
        }

        return returnData;
    }

    public static String getText(JList com) {

        String returnData = "";
        try {

            for (int i = 0; i < com.getSelectedValuesList().size(); i++) {

                ac.ui.controls.Item itemCate = (ac.ui.controls.Item) com.getSelectedValuesList().get(i);

                returnData += itemCate.getText() + ";";
            }

        } catch (Exception ex) {
        }

        return returnData;
    }
    
    
}
